/*
Author: Jason Bareswilt
Functionality: To tell the user how to play the game.
Version number: 0.0.5
Testers: needs to be tested
Date written: November 22nd 2011
Date tested: needs to be tested
*/
package disease;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class Instructions implements MouseListener
{
	public static int page = 1;
	public void instructionsGUI()
	{
		System.out.println("Instructions");
		RottingFlesh.frame.getContentPane().removeAll();
		DrawingArea drawingArea = new DrawingArea();
		ButtonPanel buttonPanel = new ButtonPanel( drawingArea );
		DrawingArea panel = new DrawingArea(new ImageIcon("ZombiesRevBInstructions.jpg").getImage());
		panel.addMouseListener(this);
		RottingFlesh.frame.getContentPane().add(panel);
		RottingFlesh.frame.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
		RottingFlesh.frame.setSize(450, 450);
		RottingFlesh.frame.setResizable(false);
		RottingFlesh.frame.setVisible(true);
	}

	static class ButtonPanel extends JPanel implements ActionListener
	{
		private static final long serialVersionUID = 1L;

		public ButtonPanel(DrawingArea drawingArea)
		{
			add( createButton("Main Menu", Color.RED) );
			add( createButton("Quit", Color.RED) );
			setBackground(Color.BLACK);
		}

		private JButton createButton(String text, Color background)
		{
			JButton button = new JButton(text);
			button.setBackground(background);
			button.addActionListener(this);
			UIManager.put("Button.select", Color.red);
			updateUI();
			return button;
		}

		public void actionPerformed(ActionEvent e)
		{
			//JButton button = (JButton)e.getSource();
			
			if ("Main Menu".equals(e.getActionCommand()))
			{
				RottingFlesh.createAndShowGUI();
			}
			if ("Quit".equals(e.getActionCommand()))
			{
				System.exit(0);
			}
		}
	}

	static class DrawingArea extends JPanel
	{
		private static final long serialVersionUID = 1L;
		private static Image img;
		public DrawingArea(String filename)
		{
			this(new ImageIcon(img).getImage());
		}
		public DrawingArea(Image img)
		{
			DrawingArea.img = img;
			Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
			setPreferredSize(size);
			setMinimumSize(size);
			setMaximumSize(size);
			setSize(size);
			setLayout(null);
	    }
		public DrawingArea()
		{

		}

		public void paintComponent(Graphics g)
		{
			g.drawImage(img, 0, 0, null);
			Font font = new Font("Serif", Font.BOLD, 14);
			Font largeFont = new Font("Serif", Font.BOLD, 16);
			g.setFont(font);
			Color transBlack = new Color(0,0,0,175);
			g.setColor(transBlack);
			g.fillRect(4, 100, 435, 250);
			g.setColor(Color.red);
			if (page == 1)
			{
				g.drawString("Prevent the spread of the zombie infection as long as you can!", 8, 120);
				g.drawString("Upgrade your city's buildings to help you hold off the infection, cure", 8, 155);
				g.drawString("people if you can and help them escape. If a building is overrun, you", 8, 170);
				g.drawString("may want to shut it down, and quarantine known infected areas.", 8, 185);
				g.drawString("Buildings: Upgrade for added benefits.  You can only upgrade them if", 8, 220);
				g.drawString("they are open.", 8, 235);
				g.drawString("Police Station - Increase the amount of police you can have to fend", 8, 270);
				g.drawString("off the zombies, and increase their strength", 8, 285);
				g.drawString("Increase your force size up to the max size, depending on level,", 8, 300);
				g.drawString("and reinforce them when they die.", 8, 315);
				g.drawString("Special: Can call on army for support and a nice strength boost.", 8, 330);
				g.setColor(Color.black);
				g.fillRect(245, 355, 100, 25);
				g.setColor(Color.red);
				g.setFont(largeFont);
				g.drawRect(245,355,100,25);
				g.drawString("Next", 275, 372);
			}
			if (page == 2)
			{
				g.drawString("Hospital - Decrease the rate of infection with upgrades, save lives of", 8, 120);
				g.drawString("citizens.", 8, 135);
				g.drawString("Special: Zombie Antidote - increases the chance to save a human", 8, 150);
				g.drawString("to 80%", 8, 165);
				g.drawString("Arena - Increase the amount of money you get, at the cost of a", 8, 200);
				g.drawString("slightly higher rate of infection.", 8, 215);
				g.drawString("Increase morale of the citizens in the area.", 8, 230);
				g.drawString("Airport - Help the people escape with the few air liners still working.", 8, 265);
				g.drawString("Upgrades cause slight increase in infection rate due to higher traffic.", 8, 280);
				g.drawString("Subway - Like the airport, but cheaper and with trains!", 8, 295);
				g.drawString("You lose once every human is a zombie or dead.", 8, 330);
				g.setColor(Color.black);
				g.fillRect(105, 355, 100, 25);
				g.setColor(Color.red);
				g.setFont(largeFont);
				g.drawString("Previous", 125, 372);
				g.drawRect(105,355,100,25);
			}
//			g.drawString("Upgrade your city's buildings to help you hold off the infection, cure people if", 8, 135);
			
		}
	}

	@Override
	public void mouseClicked(MouseEvent e1) 
	{		
		if (e1.getX() > 105 && e1.getX() < 205 && e1.getY() > 355 && e1.getY() < 380 && page == 2)
		{
			page = 1;
			RottingFlesh.frame.repaint();
		}
			
		if (e1.getX() > 245 && e1.getX() < 345 && e1.getY() > 355 && e1.getY() < 380 && page == 1)
		{
			page = 2;
			RottingFlesh.frame.repaint();
		}

	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
}
